using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//自动生成于：2021/1/29 2:32:52
namespace StarForce
{
    public partial class TypeWriterPage : UGuiForm
    {
        /// <summary>
        /// 需要展示的所有文本
        /// </summary>
        private string m_AllContent;

        /// <summary>
        /// 书写速度
        /// </summary>
        private float m_WriterSpeed;

        /// <summary>
        /// 计时
        /// </summary>
        private float m_Timing;

        /// <summary>
        /// 计数
        /// </summary>
        private int m_TimingNum;

        /// <summary>
        /// 每次打字的数量
        /// </summary>
        private int m_WriterNum;

        protected override void OnInit(object userdata)
        {
            base.OnInit(userdata);

            GetBindComponents(gameObject);
            
            m_Btn_Close.onClick.AddListener(Close);

            m_WriterSpeed = 0.2f;

            m_WriterNum = 1;
        }


        protected override void OnOpen(object userData)
        {
            base.OnOpen(userData);
            m_AllContent = "富强、民主、文明、和谐、自由、平等、公正、法治、爱国、敬业、诚信、友善。";
            m_Timing = 0;
            m_TimingNum = 1;
        }

        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            if (m_Txt_Content.text.Length != m_AllContent.Length)
            {
                if (m_Timing > m_WriterSpeed)
                {
                    m_Txt_Content.text = m_AllContent.Substring(0, m_WriterNum * m_TimingNum);
                    m_Timing = 0;
                    m_TimingNum++;
                }
                else
                {
                    m_Timing += realElapseSeconds;
                }
            }
        }
    }
}